using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Media;
using Common;
using Common.NotifyEvent;

namespace SExperiment.ExperimentResult
{
	[Serializable]
	public class Conclusion : NotNotifyPropertyChanged
	{
		[NonSerialized]
		private string _Content;

		[NonSerialized]
		private Color _Color = Colors.Black;

		public string Content
		{
			get
			{
				return _Content;
			}
			set
			{
				if (!(_Content == value))
				{
					_Content = value;
					OnPropertyChanged("Content");
				}
			}
		}

		public Color Color
		{
			get
			{
				return _Color;
			}
			set
			{
				if (!(_Color == value))
				{
					_Color = value;
					OnPropertyChanged("Color");
				}
			}
		}

		public virtual void SaveToStream(StreamEx stream)
		{
			stream.Write(PropertyKey.Key_SampleItem);
			List<PropertyKey> list = new List<PropertyKey>();
			List<byte[]> list2 = new List<byte[]>();
			if (!string.IsNullOrEmpty(Content))
			{
				list.Add(PropertyKey.Key_Content);
				list2.Add(BytesConverter.GetBytes(Content));
			}
			list.Add(PropertyKey.Key_Color);
			list2.Add(BytesConverter.GetBytes(Color.ToString()));
			stream.Write(PropertyKey.Key_Index);
			stream.WriteIndex(list, list2);
			stream.Flush();
		}

		public virtual bool ReadFromStream(StreamEx stream)
		{
			PropertyKey propertyKey = stream.ReadKey();
			if (propertyKey == PropertyKey.Key_SampleItem)
			{
				propertyKey = stream.ReadKey();
				if (propertyKey == PropertyKey.Key_Index)
				{
					List<PropertyKey> keys;
					List<byte[]> dates;
					stream.ReadIndex(out keys, out dates);
					for (int i = 0; i < keys.Count; i++)
					{
						switch (keys[i])
						{
						case PropertyKey.Key_Content:
							Content = BytesConverter.BytesToString(dates[i]);
							break;
						case PropertyKey.Key_Color:
							Color = (Color)ColorConverter.ConvertFromString(BytesConverter.BytesToString(dates[i]));
							break;
						}
					}
					return true;
				}
				stream.Seek(-4L, SeekOrigin.Current);
				return false;
			}
			stream.Seek(-4L, SeekOrigin.Current);
			return false;
		}
	}
}
